//账户类型数据
var userTypeData = [
    {id:'普通账户',text:'普通账户'},
    {id:'黑铁会员',text:'黑铁会员'},
    {id:'黄金会员',text:'黄金会员'}
];
$(".user-type-select2").select2({
    data:userTypeData
})
//data tables展示数据
$('.add').click(function(){
    $('#user-table').dataTable().fnDestroy();
    var code = $('#code').val();
    var name = $('#name').val();
    var notes = $('#notes').val();
    var status = $('input[name="status"]:checked').val();
    var userType = $('.user-type-select2 option:selected').val();
    if(!paramsCheck(new Array(code,name,notes,status,userType))){
        alert("参数不能为空！");
        return;
    }
    var params = "?code="+code+"&name="+name+"&notes="+notes+"&status="+status+"&userType="+userType;
    $.ajax({
    type: 'PUT',
    url : AjaxPath.rootPath+'/user'+params,
    params:params,
    contentType:"application/x-www-form-urlencoded",
    success : function(data){
        if(data.status == 200){
            alert("添加成功！");
            location.href="/";
        }else{
            alert(data.message);
        }
    },
    error:function(data){
        alert("添加失败！");
    }
    })
})

var paramsCheck = function(params){
    for(var i = 0; i < params.length; i++){
        if(params[i] == null || params[i] == "" || params[i] == undefined){
            return false;
        }
    }
    return true;
}





